tar xf redis-5.0.5.tar.gz

cd redis-5.0.5

make

# 配置
cp redis.conf redis.conf.bak

touch other.conf

cat > other.conf << EOF
daemonize yes
loglevel notice
logfile /var/log/redis/redis.log
EOF

# 引入other.conf
echo "include /usr/local/redis-5.0.5/other.conf" >> redis.conf

# 创建redis 日志文件夹
if [! -d "/var/log/redis" ]; then
	mkdir /var/log/redis
fi

# redis的启动警告

# 警告1 WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis.
cat >> /etc/rc.local << EOF
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
   echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
   echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi
EOF

echo never > /sys/kernel/mm/transparent_hugepage/enabled

# 警告2  WARNING: The TCP backlog setting of 511 cannot be enforced 
# 警告3 overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to/etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.

cat >> /etc/sysctl.conf << EOF
net.core.somaxconn= 1024 
vm.overcommit_memory = 1
EOF

sysctl -p

# 移动至/usr/local下
mv ../redis-5.0.5 /usr/local/

# systemctl
touch /lib/systemd/system/redis.service

cat > /lib/systemd/system/redis.service << EOF
[Unit]
Description=Redis
After=network.target
 
[Service]
Type=forking
PIDFile=/var/run/redis_6379.pid
ExecStart=/usr/local/redis-5.0.5/src/redis-server /usr/local/redis-5.0.5/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target
EOF



systemctl enable redis

systemctl start redis